///
/// $Id: modelfactory.cpp,v 1.1 2006/01/06 16:53:09 olegus Exp $
///

#include "modelfactory.h"

//////////////////////////////////////////////////////////////////////////

ModelFactory_c::ModelFactory_c ( const char * szName )
{
    Assert ( szName );
    strcpy ( m_sName, szName );
}

ModelFactory_c::~ModelFactory_c ()
{
}

//////////////////////////////////////////////////////////////////////////

StringHash_T < ModelFactory_c * > ModelFactoryStorage_c::m_dFactories;

void RegisterFactories ();

void ModelFactoryStorage_c::Init ()
{
    RegisterFactories();
}

void ModelFactoryStorage_c::Done ()
{
    m_dFactories.Delete();
}

void ModelFactoryStorage_c::Add ( ModelFactory_c * pFactory )
{
    Assert ( pFactory );
    ModelFactory_c **ppFactory = m_dFactories.Find ( pFactory->m_sName );
    if ( ppFactory != NULL )
    {
        g_cLogStdOut.Out ( "can't add factory '%s'. already exists!", pFactory->m_sName );
        return;
    }
    m_dFactories.Add ( pFactory, pFactory->m_sName );
}

ModelFactory_c * ModelFactoryStorage_c::Get ( const char * szFactory )
{
    ModelFactory_c **ppFactory = m_dFactories.Find ( szFactory );
    if ( ppFactory )
        return * ppFactory;
    else
        return NULL;
}

ModelBase_c * ModelFactoryStorage_c::Create ( const char * szFactory, const char * szModel )
{
    ModelFactory_c * pFactory = Get ( szFactory );
    if ( pFactory )
        return pFactory->Create ( szModel );
    else
        return NULL;
}

void ModelFactoryStorage_c::Report ( Log_c & cLog )
{
    HASH_FOREACH ( m_dFactories )
    {
        cLog.Out ( "%s\n", m_dFactories.Current()->m_sName );
    }
}

///
/// $Id: modelfactory.cpp,v 1.1 2006/01/06 16:53:09 olegus Exp $
///